package management;


//import com.sun.tools.javac.Main;

import wty.DatabaseChart;
import wty.Login;
import wty.Register;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Management {
    public static JPanel panel;


    private static String ID;

    public static void setID(String ID) {

        Management.ID = ID;
//        System.out.println("Management 已设置 ID: " + ID);
    }

    public static String getID(){
        return Management.ID;
    }

    public Management() {
        init();
    }

    private void init() {
        //这句不能修改
        panel = new JPanel();

        panel.setLayout(new BorderLayout(20, 20));
        panel.setBackground(Color.lightGray);


        //创建上层面板
        JPanel NorthPanel = new JPanel();
        NorthPanel.setLayout(new BorderLayout());
        NorthPanel.setBackground(Color.YELLOW);
        NorthPanel.setLayout(new BorderLayout());

        JLabel welcomeLabel = new JLabel("Welcome to Management System!");
        welcomeLabel.setForeground(Color.BLACK);
        welcomeLabel.setFont(new Font("Serif", Font.BOLD, 50));


        NorthPanel.add(welcomeLabel, BorderLayout.WEST);
//        panel.add(NorthPanel, BorderLayout.NORTH); // 放在顶部




        // 创建按钮面板
        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new GridLayout(3, 2, 10, 10)); // 2行2列的网格布局
        buttonPanel.setBackground(Color.lightGray); // 保持与主面板一致的背景色

        // 创建增、删、改、查、、按钮
        JButton addButton = new JButton("Add");
        JButton deleteButton = new JButton("Delete");
        JButton updateButton = new JButton("Update");
        JButton queryButton = new JButton("Query");
        JButton CategoryAddButton = new JButton("Category Add");
        JButton ChartButton = new JButton("Chart");
        JButton CategoryDeleteButton = new JButton("Category Delete");

        // 设置按钮的字体和背景颜色,属于总体的
        Font buttonFont = new Font("Arial", Font.BOLD, 24);
        Color buttonColor = new Color(0, 102, 204); // 深蓝色


        addButton.addActionListener(
                new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Add add = new Add();
                        add.AddFace();
                    }
                }
        );

        deleteButton.addActionListener(
                new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Delete delete = new Delete();
                        delete.window();
                    }
                }
        );

        updateButton.addActionListener(
                new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        //-------------------------------------------------------
                        Modify modify = new Modify();
                        modify.ModifyWindow();
                    }
                }
        );



        queryButton.addActionListener(
                new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Query q = new Query();
                        q.QFace();
                    }
                }
        );


        CategoryAddButton.addActionListener(
                new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Category category =new Category();
                        // category.DeleteCategoryWindow();
                        category.AddCategoryWindow();
                    }
                }
        );


        ChartButton.addActionListener(
                new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
//                        DatabaseChart db = new DatabaseChart();

                            DatabaseChart demo = new DatabaseChart();
                            //注释下面一句，保证图标窗口关闭后程序能够继续运行
//                            demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                            demo.pack();
                            demo.setVisible(true);

                    }
                }
        );

        CategoryDeleteButton.addActionListener(
                new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Category category =new Category();
                         category.DeleteCategoryWindow();
                    }
                }
        );


        addButton.setFont(buttonFont);
        addButton.setBackground(buttonColor);
        addButton.setForeground(Color.WHITE);

        deleteButton.setFont(buttonFont);
        deleteButton.setBackground(buttonColor);
        deleteButton.setForeground(Color.WHITE);

        updateButton.setFont(buttonFont);
        updateButton.setBackground(buttonColor);
        updateButton.setForeground(Color.WHITE);

        queryButton.setFont(buttonFont);
        queryButton.setBackground(buttonColor);
        queryButton.setForeground(Color.WHITE);

        CategoryAddButton.setFont(buttonFont);
        CategoryAddButton.setBackground(buttonColor);
        CategoryAddButton.setForeground(Color.WHITE);

        ChartButton.setFont(buttonFont);
        ChartButton.setBackground(buttonColor);
        ChartButton.setForeground(Color.WHITE);

        CategoryDeleteButton.setFont(buttonFont);
        CategoryDeleteButton.setBackground(buttonColor);
        CategoryDeleteButton.setForeground(Color.WHITE);

        // 将按钮添加到按钮面板
        buttonPanel.add(addButton);
        buttonPanel.add(deleteButton);
        buttonPanel.add(updateButton);
        buttonPanel.add(queryButton);
        buttonPanel.add(CategoryAddButton);
//        buttonPanel.add(ChartButton);
        buttonPanel.add(CategoryDeleteButton);




        NorthPanel.add(ChartButton, BorderLayout.EAST);
        panel.add(NorthPanel, BorderLayout.NORTH); // 放在顶部

        // 将按钮面板添加到主面板的中心
        panel.add(buttonPanel, BorderLayout.CENTER);


        JButton backButton = new JButton("Back");
        backButton.setFont(new Font("Arial", Font.PLAIN, 28));
        backButton.addActionListener(
                new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Management.panel.setVisible(false);
                        Login.panel.setVisible(true);
                    }
                }
        );

        panel.add(backButton, BorderLayout.SOUTH);

    }
}

